﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Daco.Web.Store
{
    using Data = Web.Data;

    public enum EPhotoType
    {
        Product,
        Common
    }

    public class CPhoto
    {
        #region Properties
        public string PhotoID
        {
            get;
            private set;
        }

        public string Title
        {
            get;
            set;
        }

        protected EPhotoType PhotoType
        {
            get;
            set;
        }

        public string ThumbFileName
        {
            get;
            set;
        }

        public string LargeFileName
        {
            get;
            set;
        }

        public bool Primary
        {
            get;
            set;
        }
        #endregion

        #region Constructors
        public CPhoto()
        {
            this.PhotoID = "FFFFFFFF";
        }
        public CPhoto(string photoID)
        {
            this.PhotoID = photoID;
            this.PhotoType = EPhotoType.Common;
        }
        public CPhoto(EPhotoType photoType)
            : this()
        {
            this.PhotoType = EPhotoType.Common;
        }
        public CPhoto(string photoID, EPhotoType photoType)
        {
            this.PhotoID = photoID;
            this.PhotoType = photoType;
        }
        public CPhoto(string photoID, string title, string thumbFileName, string largeFileName, bool primary)
        {
            this.PhotoID = photoID;
            this.Title = title;
            this.ThumbFileName = thumbFileName;
            this.LargeFileName = largeFileName;
            this.Primary = primary;
        }
        #endregion

        public bool Delete()
        {
            bool success = CPhoto.DeletePhoto(this.PhotoID);
            if (success) this.PhotoID = string.Empty;
            return success;
        }

        public static bool DeletePhoto(string photoID)
        {
            bool success = Providers.CStoreProvider.Instance.DeletePhoto(photoID);
            return success;
        }

        public static string AddPhoto(string productID, string title, string thumbFileName, byte[] thumbPhoto, string largeFileName, byte[] largePhoto, bool primary)
        {
            string photoID = Daco.Utils.CHelper.GenerateString(8);

            photoID = Providers.CStoreProvider.Instance.AddPhoto(photoID, productID, title, thumbFileName, thumbPhoto, largeFileName, largePhoto, primary);

            return photoID;
        }

        public static List<CPhoto> GetPhotos(string productID)
        {
            List<CPhoto> photos = new List<CPhoto>(Providers.CStoreProvider.Instance.GetPhotos(productID));
            return photos;
        }

        public static byte[] GetPhotoContent(string photoID, bool largePhoto)
        {
            byte[] content = Providers.CStoreProvider.Instance.GetPhotoContent(photoID, largePhoto);
            return content;
        }
    }
}
